<template>
    <Modal
            width="500"
            v-model="visible"
            title="上报月度设定"
            :key="key"
    >
        <Spin size="large" fix v-if="Loading"></Spin>
        <Form ref="formData" :model="formData" :rules="rules" :label-width="150">
            <FormItem label="数据月度" prop="prnt0001">
                <DatePicker type="month" v-model="formData.prnt0001" style="width: 150px"
                            format="yyyy-MM"  :editable="false"></DatePicker>
            </FormItem>
        </Form>
        <div slot="footer">
            <Button type="text" size="large" @click="cancel">取消</Button>
            <Button type="primary" size="large" @click="ok">确定</Button>
        </div>
    </Modal>
</template>

<script>
    import {postAction} from '@/api/request'

    export default {
        name: "ls-report-add-modal",
        data() {
            return {
                formData: {},
                title: "上报月度设定",
                visible: false,
                key: "",
                rules: {
                    prnt0001: [
                        {required: true, message: '请选择数据月度', trigger: 'change', type: 'date'}
                    ],
                },
                Loading: false,
                url: "/api/ac/subsistence/ss00028Service/insert",
            }
        },
        methods: {
            cancel() {
                this.visible = false;
            },
            add() {
                this.formData = {};
                this.visible = true;
            },
            ok() {
                let that = this;
                this.$refs['formData'].validate((valid) => {
                    if (valid) {
                        that.submitFrom();
                    }
                })
            },
            submitFrom() {
                var that = this;
                that.Loading = true;
                var prnt0001 = this.formData.prnt0001;
                if (this.formData.prnt0001) {
                    prnt0001 = this.DateFormat(prnt0001, 'YYYY-MM');
                }
                postAction(this.url, {prnt0001: prnt0001}).then((res) => {
                    if (res.data.errcode != 0) {
                        this.$Message.error(res.data.errmsg);
                    } else {
                        that.$Message.success("保存完成！");
                        this.$emit('ok');
                        this.visible = false;
                    }
                }).finally(() => {
                    that.Loading = false;
                });
            }
        }
    }
</script>

<style scoped>

</style>